package com.itheima.mapper;

import com.itheima.dto.EmpDto;
import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.*;


import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {



    /**
     * 根据id删除员工
     *
     * @param id
     */
    @Delete("delete from emp where id = #{id}")
    void DeleteEmpById(@Param("id") Integer id);

    /**
     * 新增员工
     *
     * @param emp
     */

    @Insert("insert into emp(username, name, gender, image, job, " +
            "entrydate, dept_id, create_time, update_time) " +
            "values (#{username}, #{name}, #{gender}, #{image}, #{job}, #{entrydate}, #{deptId}, #{createTime}, #{updateTime})")
    void insert(Emp emp);

    /**
     * 更新员工
     *
     * @param emp
     */
    @Update("update emp set username=#{username}, name=#{name}, gender=#{gender}," +
            " image=#{image}, job=#{job}, entrydate=#{entrydate}, dept_id=#{deptId}, " +
            "update_time=#{updateTime} where id=#{id}")
    void UpdateEmp(Emp emp);

    /**
     * 根据id查询员工
     *
     * @param id
     * @return
     */
    @Select("select * from emp where id = #{id}")
    Emp selectEmpById(@Param("id") Integer id);

    /**
     * 根据条件查询员工
     *
     * @param name
     * @param gender
     * @param begin
     * @param end
     * @return
     */
    @Select("select * from emp ")
    List<Emp> list(@Param("name") String name, @Param("gender") Short gender, @Param("begin") LocalDate begin,@Param("end") LocalDate end);

    /**
     * 根据条件查询员工
     * @param empDto
     * @return
     */
    @Select("select * from emp where name like concat('%',#{empDto.name},'%')" +
            " and gender =#{empDto.gender}" +
            " and entrydate between #{empDto.begin}" +
            " and #{empDto.end}"
    )
    List<Emp>SelectEmpByCondition(@Param("empDto")EmpDto empDto);
}
